﻿@using Microsoft.AspNet.Identity.EntityFramework
@{
    ViewBag.Title = "角色维护";
}


@( Html.Kendo().Grid<IdentityRole>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(p => p.Name).Title("角色名称").Filterable(f => f.Operators(o => o.ForString(d => d.Clear().IsEqualTo("等于").Contains("包含")))).Width(125);
                columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
            })
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .HtmlAttributes(new { style = "height: 550px;" })
            .Filterable()
            .Pageable()
            .Navigatable()
            .Sortable()
            .Scrollable(scr => scr.Height(550))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .Events(events => events.Error("error_handler"))
                .ServerOperation(false)
                .Model(model => model.Id(p => p.Id))
                .Create(update => update.Action("Role_Create", "RolesAdmin"))
            .Read(read => read.Action("Roles_Read", "RolesAdmin"))
            .Update(update => update.Action("Role_Update", "RolesAdmin"))
            .Destroy(update => update.Action("Role_Destroy", "RolesAdmin"))
            )
      )

<script type="text/javascript">
        function error_handler(e) {
            if (e.errors) {
                var message = "Errors:\n";
                $.each(e.errors, function (key, value) {
                    if ('errors' in value) {
                        $.each(value.errors, function () {
                            message += this + "\n";
                        });
                    }
                });
                alert(message);
            }
        }

        $(".sidebar-menu li").removeClass("active");
        $("#role").addClass("active");
</script>